import Vue from 'vue';
import Router from 'vue-router';
import i18n from 'vue-i18n';
import App from './container/App.vue';
import Home from './container/Home.vue'
import TaskView from './container/Task.vue';
import ResultList from './container/ResultList.vue';
import CaseView from './container/CaseView.vue';

// helper
import {formatDate, formatTime, formatLog} from './filter';
import {lcCode, lcCodeMark} from './directive';

// css
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import 'sublemon/theme.css';
import './global.css';
import './icon.css';
import './env.css';

Vue.use(Router);
Vue.use(i18n);
Vue.filter('date', formatDate);
Vue.filter('time', formatTime);
Vue.filter('logBody', formatLog);
Vue.directive('code', lcCode);
Vue.directive('code-mark', lcCodeMark);

Vue.config.lang = 'en-us';
Vue.locale('en-us', require('./lang/en-us.json'));
Vue.locale('zh-cn', require('./lang/zh-cn.json'));

var router = new Router();

router.map({
	'/': {
		name: 'home',
		component: Home
	},
	'/project/:projectId/task/public': {
		name: 'taskList',
		component: TaskView
	},
	'/project/:projectId/task/:taskId/result': {
		name: 'resultList',
		component: ResultList
	},
	'/project/:projectId/task/:taskId/result/case/:caseIndex': {
		name: 'caseResult',
		component: CaseView
	}
});

router.beforeEach(() => window.scrollTo(0, 0));

router.redirect({
	// when all route match fail, goto home page
	'*': '/'
});

router.start(App, '#app');

module.exports = router;
